
class EventArgs(object):
  def __init__(self, value):
    assert type(value) == type(())
    self._value = value

  def getValue(self):
    return self._value

class EventHandler(object):
  def __init__(self):
    self._handlers = []

  def add(self, handler):
    if self._handlers.__contains__(handler):
      return
    self._handlers.append(handler)

  def remove(self, handler):
    if self._handlers.__contains__(handler):
      self._handlers.remove(handler)

  def invoke(self, sender, args):
    assert type(args) is EventArgs
    for handler in self._handlers:
      handler(sender, args)


##############################################################
## test codes
if __name__ == '__main__':
  class A(object):
    def __init__(self): 
      self._callBackEventHandler = EventHandler()

    def callBackEventHander(self, handler):
      self._callBackEventHandler.add(handler)

    def callBack(self):
      args = EventArgs(('Class A called this method of ',))
      self._callBackEventHandler.invoke(self, args)

  class B(object):
    def __init__(self):
      pass

    def processer(self, sender, args):
      print 'Sender type is %s. %s B class.' % (type(sender), args.getValue()[0])

  class C(object):
    def __init__(self):
      pass

    def processer(self, sender, args):
      print 'Sender type is %s. %s C class.' % (type(sender), args.getValue()[0])

  a = A()
  b = B()
  c = C()

  a.callBackEventHander(b.processer)
  a.callBackEventHander(c.processer)
  a.callBack()
